package com.sky.mapper;


import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {


    void add(AddressBook addressBook);


    //--2--查询当前登录用户的所有地址信息
    @Select("select * from address_book where user_id =#{currentId} order by is_default desc ")
    List<AddressBook> selectList(Long currentId);



    //--4--根据id修改地址
    void updateByUserId(AddressBook addressBook);


    //--5--根据id删除地址
    @Delete("delete from address_book where id=#{id}")
    void deleteById(Long id);


    //--6--根据id查询地址
    @Select("select * from address_book where id=#{id}")
    AddressBook selectById(Long id);


    @Select("select * from address_book where is_default=1 and user_id =#{currentId}")
    AddressBook selectdefault(Long currentId);

    //当前用户所有地址（不默认）
    @Update("update address_book set is_default=0 where user_id =#{currentId}")
    void notListDefault(Long currentId);

    //当前地址（默认）
    @Update("update address_book set is_default=1 where id =#{id}")
    void isOneDefault(Long id);
}
